package design.principles.ocp.before;

import java.util.Iterator;
import java.util.List;

public class ShapeUtil {

    static void printArea(List shapes) {
        Iterator it = shapes.iterator();
        while (it.hasNext()) {
            double area = 0;
            Object shape = it.next();
            if (shape instanceof Square) {
                area = ((Square) shape).getLength() * ((Square) shape).getLength();
            }
            else if (shape instanceof Circle) {
                area = Math.PI * ((Circle) shape).getRadius() * ((Circle) shape).getRadius();
            }
            else if (shape instanceof Triangle) {
                area = 0.5 * ((Triangle) shape).getBase() * ((Triangle) shape).getHeight();
            }
            System.out.println("Area of " + shape.getClass().getSimpleName() + " is: " + area);
        }
    }
}
